package org.estela.ml.dataset;


public class ContinuousAttribute extends AbstractAttribute {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 
	 *
	 */
	public ContinuousAttribute() {
		super();
	}
	
	/**
	 * 
	 * @param index
	 * @param name
	 */
	public ContinuousAttribute(int index, String name) {
		super(index, name);
	}

	/**
	 * 
	 * @param index
	 * @param name
	 * @param weight
	 */
	public ContinuousAttribute(int index, String name, double weight) {
		super(index, name, weight);
	}



	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	/*
	 *  (non-Javadoc)
	 * @see dataset.Attribute#encode(java.lang.Object)
	 */
	public double encode(Object value) {
		System.out.println("value: " + value);
		double d = value == null ? Double.NaN : Double.parseDouble(value.toString());
		System.out.println("d: " + d);
		return d;
	}

	/*
	 *  (non-Javadoc)
	 * @see dataset.Attribute#decode(double)
	 */
	public Object decode(double d) {
		if (d == Double.NaN) {
			return null;
		}
		return d;
	}

	/*
	 *  (non-Javadoc)
	 * @see dataset.Attribute#isDiscrete()
	 */
	public boolean isDiscrete() {
		return false;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ContinuousAttribute) {
			ContinuousAttribute continuousAttribute = (ContinuousAttribute) obj;
			return this.name.equals(continuousAttribute.name);
		}
		return false;
	}
	
	@Override
	public String toString() {
		StringBuilder buff = new StringBuilder();
		buff.append("[ContinuousAttribute name=").append(this.name);
		buff.append(", weight=").append(this.weight);
		buff.append(", index=").append(this.index);
		buff.append(']');
		return buff.toString();
	}
	

}